import React, { Component } from 'react'

export default class Search extends Component {
    constructor () {
        super();
        this.state = {
            key: '',
            stocked: false,
        }
    }
    changeSearchInfo = (checked, varType) => {
        this.setState({
            [varType]: checked
        }, () => {
            this.props.search(this.state.key, this.state.stocked)
        })
    }
    render() {
        return (
            <div style={{ textAlign: 'center' }}>
                <input value={this.state.key} onChange={(e) => { this.changeSearchInfo(e.target.value, 'key') }} />
                <br></br>
                <input type='checkbox' checked={this.state.stocked} onChange={(e) => { this.changeSearchInfo(e.target.checked, 'stocked') }} />显示有库存
            </div>
        )
    }
}
